<?php
session_start(); // Initialize Session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg7.php" ?>
<?php include "ewmysql7.php" ?>
<?php include "phpfn7.php" ?>
<?php include "psacar_newsinfo.php" ?>
<?php include "psacar_userinfo.php" ?>
<?php include "userfn7.php" ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php

// Create page object
$psacar_news_edit = new cpsacar_news_edit();
$Page =& $psacar_news_edit;

// Page init
$psacar_news_edit->Page_Init();

// Page main
$psacar_news_edit->Page_Main();
?>
<?php include "header.php" ?>
<script type="text/javascript">
<!--

// Create page object
var psacar_news_edit = new ew_Page("psacar_news_edit");

// page properties
psacar_news_edit.PageID = "edit"; // page ID
psacar_news_edit.FormID = "fpsacar_newsedit"; // form ID
var EW_PAGE_ID = psacar_news_edit.PageID; // for backward compatibility

// extend page with ValidateForm function
psacar_news_edit.ValidateForm = function(fobj) {
	ew_PostAutoSuggest(fobj);
	if (!this.ValidateRequired)
		return true; // ignore validation
	if (fobj.a_confirm && fobj.a_confirm.value == "F")
		return true;
	var i, elm, aelm, infix;
	var rowcnt = (fobj.key_count) ? Number(fobj.key_count.value) : 1;
	for (i=0; i<rowcnt; i++) {
		infix = (fobj.key_count) ? String(i+1) : "";
		elm = fobj.elements["x" + infix + "_notify"];
		if (elm && !ew_CheckInteger(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_news->notify->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_post_date"];
		if (elm && !ew_CheckDate(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_news->post_date->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_created_date"];
		if (elm && !ew_CheckDate(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_news->created_date->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_modified_date"];
		if (elm && !ew_CheckDate(elm.value))
			return ew_OnError(this, elm, "<?php echo ew_JsEncode2($psacar_news->modified_date->FldErrMsg()) ?>");
		elm = fobj.elements["x" + infix + "_image_news"];
		if (elm && !ew_CheckFileType(elm.value))
			return ew_OnError(this, elm, ewLanguage.Phrase("WrongFileType"));
		elm = fobj.elements["x" + infix + "_thumbnail_news"];
		if (elm && !ew_CheckFileType(elm.value))
			return ew_OnError(this, elm, ewLanguage.Phrase("WrongFileType"));

		// Call Form Custom Validate event
		if (!this.Form_CustomValidate(fobj)) return false;
	}
	return true;
}

// extend page with Form_CustomValidate function
psacar_news_edit.Form_CustomValidate =  
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
<?php if (EW_CLIENT_VALIDATE) { ?>
psacar_news_edit.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
psacar_news_edit.ValidateRequired = false; // no JavaScript validation
<?php } ?>

//-->
</script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
<!--
_width_multiplier = 20;
_height_multiplier = 60;
var ew_DHTMLEditors = [];

// update value from editor to textarea
function ew_UpdateTextArea() {
	if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {			
		var inst;			
		for (inst in CKEDITOR.instances)
			CKEDITOR.instances[inst].updateElement();
	}
}

// update value from textarea to editor
function ew_UpdateDHTMLEditor(name) {
	if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {
		var inst = CKEDITOR.instances[name];		
		if (inst)
			inst.setData(inst.element.value);
	}
}

// focus editor
function ew_FocusDHTMLEditor(name) {
	if (typeof ew_DHTMLEditors != 'undefined' && typeof CKEDITOR != 'undefined') {
		var inst = CKEDITOR.instances[name];	
		if (inst)
			inst.focus();
	}
}

//-->
</script>
<link rel="stylesheet" type="text/css" media="all" href="calendar/calendar-win2k-cold-1.css" title="win2k-1">
<script type="text/javascript" src="calendar/calendar.js"></script>
<script type="text/javascript" src="calendar/lang/calendar-en.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->

</script>
<p><span class="phpmaker"><?php echo $Language->Phrase("Edit") ?>&nbsp;<?php echo $Language->Phrase("TblTypeTABLE") ?><?php echo $psacar_news->TableCaption() ?><br><br>
<a href="<?php echo $psacar_news->getReturnUrl() ?>"><?php echo $Language->Phrase("GoBack") ?></a></span></p>
<?php
if (EW_DEBUG_ENABLED)
	echo ew_DebugMsg();
$psacar_news_edit->ShowMessage();
?>
<form name="fpsacar_newsedit" id="fpsacar_newsedit" action="<?php echo ew_CurrentPage() ?>" method="post" enctype="multipart/form-data" onsubmit="return psacar_news_edit.ValidateForm(this);">
<p>
<input type="hidden" name="a_table" id="a_table" value="psacar_news">
<input type="hidden" name="a_edit" id="a_edit" value="U">
<table cellspacing="0" class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable">
<?php if ($psacar_news->id->Visible) { // id ?>
	<tr<?php echo $psacar_news->id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_news->id->FldCaption() ?></td>
		<td<?php echo $psacar_news->id->CellAttributes() ?>><span id="el_id">
<div<?php echo $psacar_news->id->ViewAttributes() ?>><?php echo $psacar_news->id->EditValue ?></div><input type="hidden" name="x_id" id="x_id" value="<?php echo ew_HtmlEncode($psacar_news->id->CurrentValue) ?>">
</span><?php echo $psacar_news->id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_news->news_cat_id->Visible) { // news_cat_id ?>
	<tr<?php echo $psacar_news->news_cat_id->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_news->news_cat_id->FldCaption() ?></td>
		<td<?php echo $psacar_news->news_cat_id->CellAttributes() ?>><span id="el_news_cat_id">
<select id="x_news_cat_id" name="x_news_cat_id" title="<?php echo $psacar_news->news_cat_id->FldTitle() ?>"<?php echo $psacar_news->news_cat_id->EditAttributes() ?>>
<?php
if (is_array($psacar_news->news_cat_id->EditValue)) {
	$arwrk = $psacar_news->news_cat_id->EditValue;
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = (strval($psacar_news->news_cat_id->CurrentValue) == strval($arwrk[$rowcntwrk][0])) ? " selected=\"selected\"" : "";
		if ($selwrk <> "") $emptywrk = FALSE;
?>
<option value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?>>
<?php echo $arwrk[$rowcntwrk][1] ?>
</option>
<?php
	}
}
?>
</select>
</span><?php echo $psacar_news->news_cat_id->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_news->title->Visible) { // title ?>
	<tr<?php echo $psacar_news->title->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_news->title->FldCaption() ?></td>
		<td<?php echo $psacar_news->title->CellAttributes() ?>><span id="el_title">
<input type="text" name="x_title" id="x_title" title="<?php echo $psacar_news->title->FldTitle() ?>" size="30" maxlength="50" value="<?php echo $psacar_news->title->EditValue ?>"<?php echo $psacar_news->title->EditAttributes() ?>>
</span><?php echo $psacar_news->title->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_news->name->Visible) { // name ?>
	<tr<?php echo $psacar_news->name->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_news->name->FldCaption() ?></td>
		<td<?php echo $psacar_news->name->CellAttributes() ?>><span id="el_name">
<input type="text" name="x_name" id="x_name" title="<?php echo $psacar_news->name->FldTitle() ?>" size="30" maxlength="15" value="<?php echo $psacar_news->name->EditValue ?>"<?php echo $psacar_news->name->EditAttributes() ?>>
</span><?php echo $psacar_news->name->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_news->short_description->Visible) { // short_description ?>
	<tr<?php echo $psacar_news->short_description->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_news->short_description->FldCaption() ?></td>
		<td<?php echo $psacar_news->short_description->CellAttributes() ?>><span id="el_short_description">
<textarea name="x_short_description" id="x_short_description" title="<?php echo $psacar_news->short_description->FldTitle() ?>" cols="35" rows="4"<?php echo $psacar_news->short_description->EditAttributes() ?>><?php echo $psacar_news->short_description->EditValue ?></textarea>
</span><?php echo $psacar_news->short_description->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_news->description->Visible) { // description ?>
	<tr<?php echo $psacar_news->description->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_news->description->FldCaption() ?></td>
		<td<?php echo $psacar_news->description->CellAttributes() ?>><span id="el_description">
<textarea name="x_description" id="x_description" title="<?php echo $psacar_news->description->FldTitle() ?>" cols="40" rows="10"<?php echo $psacar_news->description->EditAttributes() ?>><?php echo $psacar_news->description->EditValue ?></textarea>
<script type="text/javascript">
<!--
ew_DHTMLEditors.push(new ew_DHTMLEditor("x_description", function() {
    var oCKeditor = CKEDITOR.replace(
        'x_description', 
        { 
            width: 40 * _width_multiplier, 
            height: 10 * _height_multiplier, 
            autoUpdateElement: false, 
            baseHref: 'ckeditor/'
        });
    this.active = true;
}));
-->
</script>
</span><?php echo $psacar_news->description->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_news->notify->Visible) { // notify ?>
	<tr<?php echo $psacar_news->notify->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_news->notify->FldCaption() ?></td>
		<td<?php echo $psacar_news->notify->CellAttributes() ?>><span id="el_notify">
<input type="text" name="x_notify" id="x_notify" title="<?php echo $psacar_news->notify->FldTitle() ?>" size="30" value="<?php echo $psacar_news->notify->EditValue ?>"<?php echo $psacar_news->notify->EditAttributes() ?>>
</span><?php echo $psacar_news->notify->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_news->is_show->Visible) { // is_show ?>
	<tr<?php echo $psacar_news->is_show->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_news->is_show->FldCaption() ?></td>
		<td<?php echo $psacar_news->is_show->CellAttributes() ?>><span id="el_is_show">
<div id="tp_x_is_show" class="<?php echo EW_ITEM_TEMPLATE_CLASSNAME; ?>"><input type="checkbox" name="x_is_show[]" id="x_is_show[]" title="<?php echo $psacar_news->is_show->FldTitle() ?>" value="{value}"<?php echo $psacar_news->is_show->EditAttributes() ?>></div>
<div id="dsl_x_is_show" repeatcolumn="5">
<?php
$arwrk = $psacar_news->is_show->EditValue;
if (is_array($arwrk)) {
	$armultiwrk= explode(",", strval($psacar_news->is_show->CurrentValue));
	$rowswrk = count($arwrk);
	$emptywrk = TRUE;
	for ($rowcntwrk = 0; $rowcntwrk < $rowswrk; $rowcntwrk++) {
		$selwrk = "";
		for ($ari = 0; $ari < count($armultiwrk); $ari++) {
			if (strval($arwrk[$rowcntwrk][0]) == trim(strval($armultiwrk[$ari]))) {
				$selwrk = " checked=\"checked\"";
				if ($selwrk <> "") $emptywrk = FALSE;
				break;
			}
		}

		// Note: No spacing within the LABEL tag
?>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 1) ?>
<label><input type="checkbox" name="x_is_show[]" id="x_is_show[]" title="<?php echo $psacar_news->is_show->FldTitle() ?>" value="<?php echo ew_HtmlEncode($arwrk[$rowcntwrk][0]) ?>"<?php echo $selwrk ?><?php echo $psacar_news->is_show->EditAttributes() ?>><?php echo $arwrk[$rowcntwrk][1] ?></label>
<?php echo ew_RepeatColumnTable($rowswrk, $rowcntwrk, 5, 2) ?>
<?php
	}
}
?>
</div>
</span><?php echo $psacar_news->is_show->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_news->post_date->Visible) { // post_date ?>
	<tr<?php echo $psacar_news->post_date->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_news->post_date->FldCaption() ?></td>
		<td<?php echo $psacar_news->post_date->CellAttributes() ?>><span id="el_post_date">
<input type="text" name="x_post_date" id="x_post_date" title="<?php echo $psacar_news->post_date->FldTitle() ?>" value="<?php echo $psacar_news->post_date->EditValue ?>"<?php echo $psacar_news->post_date->EditAttributes() ?>>
&nbsp;<img src="images/calendar.png" id="cal_x_post_date" name="cal_x_post_date" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
	inputField: "x_post_date", // input field id
	ifFormat: "%Y/%m/%d", // date format
	button: "cal_x_post_date" // button id
});
</script>
</span><?php echo $psacar_news->post_date->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_news->created_date->Visible) { // created_date ?>
	<tr<?php echo $psacar_news->created_date->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_news->created_date->FldCaption() ?></td>
		<td<?php echo $psacar_news->created_date->CellAttributes() ?>><span id="el_created_date">
<input type="text" name="x_created_date" id="x_created_date" title="<?php echo $psacar_news->created_date->FldTitle() ?>" value="<?php echo $psacar_news->created_date->EditValue ?>"<?php echo $psacar_news->created_date->EditAttributes() ?>>
&nbsp;<img src="images/calendar.png" id="cal_x_created_date" name="cal_x_created_date" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
	inputField: "x_created_date", // input field id
	ifFormat: "%Y/%m/%d", // date format
	button: "cal_x_created_date" // button id
});
</script>
</span><?php echo $psacar_news->created_date->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_news->modified_date->Visible) { // modified_date ?>
	<tr<?php echo $psacar_news->modified_date->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_news->modified_date->FldCaption() ?></td>
		<td<?php echo $psacar_news->modified_date->CellAttributes() ?>><span id="el_modified_date">
<input type="text" name="x_modified_date" id="x_modified_date" title="<?php echo $psacar_news->modified_date->FldTitle() ?>" value="<?php echo $psacar_news->modified_date->EditValue ?>"<?php echo $psacar_news->modified_date->EditAttributes() ?>>
&nbsp;<img src="images/calendar.png" id="cal_x_modified_date" name="cal_x_modified_date" alt="<?php echo $Language->Phrase("PickDate") ?>" title="<?php echo $Language->Phrase("PickDate") ?>" style="cursor:pointer;cursor:hand;">
<script type="text/javascript">
Calendar.setup({
	inputField: "x_modified_date", // input field id
	ifFormat: "%Y/%m/%d", // date format
	button: "cal_x_modified_date" // button id
});
</script>
</span><?php echo $psacar_news->modified_date->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_news->image_news->Visible) { // image_news ?>
	<tr<?php echo $psacar_news->image_news->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_news->image_news->FldCaption() ?></td>
		<td<?php echo $psacar_news->image_news->CellAttributes() ?>><span id="el_image_news">
<div id="old_x_image_news">
<?php if ($psacar_news->image_news->HrefValue <> "" || $psacar_news->image_news->TooltipValue <> "") { ?>
<?php if (!empty($psacar_news->image_news->Upload->DbValue)) { ?>
<a href="<?php echo $psacar_news->image_news->HrefValue ?>"><?php echo $psacar_news->image_news->EditValue ?></a>
<?php } elseif (!in_array($psacar_news->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } else { ?>
<?php if (!empty($psacar_news->image_news->Upload->DbValue)) { ?>
<?php echo $psacar_news->image_news->EditValue ?>
<?php } elseif (!in_array($psacar_news->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } ?>
</div>
<div id="new_x_image_news">
<?php if (!empty($psacar_news->image_news->Upload->DbValue)) { ?>
<label><input type="radio" name="a_image_news" id="a_image_news" value="1" checked="checked"><?php echo $Language->Phrase("Keep") ?></label>&nbsp;
<label><input type="radio" name="a_image_news" id="a_image_news" value="2"><?php echo $Language->Phrase("Remove") ?></label>&nbsp;
<label><input type="radio" name="a_image_news" id="a_image_news" value="3"><?php echo $Language->Phrase("Replace") ?><br></label>
<?php $psacar_news->image_news->EditAttrs["onchange"] = "this.form.a_image_news[2].checked=true;" . @$psacar_news->image_news->EditAttrs["onchange"]; ?>
<?php } else { ?>
<input type="hidden" name="a_image_news" id="a_image_news" value="3">
<?php } ?>
<input type="file" name="x_image_news" id="x_image_news" title="<?php echo $psacar_news->image_news->FldTitle() ?>" size="30"<?php echo $psacar_news->image_news->EditAttributes() ?>>
</div>
</span><?php echo $psacar_news->image_news->CustomMsg ?></td>
	</tr>
<?php } ?>
<?php if ($psacar_news->thumbnail_news->Visible) { // thumbnail_news ?>
	<tr<?php echo $psacar_news->thumbnail_news->RowAttributes ?>>
		<td class="ewTableHeader"><?php echo $psacar_news->thumbnail_news->FldCaption() ?></td>
		<td<?php echo $psacar_news->thumbnail_news->CellAttributes() ?>><span id="el_thumbnail_news">
<div id="old_x_thumbnail_news">
<?php if ($psacar_news->thumbnail_news->HrefValue <> "" || $psacar_news->thumbnail_news->TooltipValue <> "") { ?>
<?php if (!empty($psacar_news->thumbnail_news->Upload->DbValue)) { ?>
<img src="<?php echo ew_UploadPathEx(FALSE, $psacar_news->thumbnail_news->UploadPath) . $psacar_news->thumbnail_news->Upload->DbValue ?>" border=0<?php echo $psacar_news->thumbnail_news->ViewAttributes() ?>>
<?php } elseif (!in_array($psacar_news->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } else { ?>
<?php if (!empty($psacar_news->thumbnail_news->Upload->DbValue)) { ?>
<img src="<?php echo ew_UploadPathEx(FALSE, $psacar_news->thumbnail_news->UploadPath) . $psacar_news->thumbnail_news->Upload->DbValue ?>" border=0<?php echo $psacar_news->thumbnail_news->ViewAttributes() ?>>
<?php } elseif (!in_array($psacar_news->CurrentAction, array("I", "edit", "gridedit"))) { ?>	
&nbsp;
<?php } ?>
<?php } ?>
</div>
<div id="new_x_thumbnail_news">
<?php if (!empty($psacar_news->thumbnail_news->Upload->DbValue)) { ?>
<label><input type="radio" name="a_thumbnail_news" id="a_thumbnail_news" value="1" checked="checked"><?php echo $Language->Phrase("Keep") ?></label>&nbsp;
<label><input type="radio" name="a_thumbnail_news" id="a_thumbnail_news" value="2"><?php echo $Language->Phrase("Remove") ?></label>&nbsp;
<label><input type="radio" name="a_thumbnail_news" id="a_thumbnail_news" value="3"><?php echo $Language->Phrase("Replace") ?><br></label>
<?php $psacar_news->thumbnail_news->EditAttrs["onchange"] = "this.form.a_thumbnail_news[2].checked=true;" . @$psacar_news->thumbnail_news->EditAttrs["onchange"]; ?>
<?php } else { ?>
<input type="hidden" name="a_thumbnail_news" id="a_thumbnail_news" value="3">
<?php } ?>
<input type="file" name="x_thumbnail_news" id="x_thumbnail_news" title="<?php echo $psacar_news->thumbnail_news->FldTitle() ?>" size="30"<?php echo $psacar_news->thumbnail_news->EditAttributes() ?>>
</div>
</span><?php echo $psacar_news->thumbnail_news->CustomMsg ?></td>
	</tr>
<?php } ?>
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="btnAction" id="btnAction" value="<?php echo ew_BtnCaption($Language->Phrase("EditBtn")) ?>">
</form>
<script type="text/javascript">
<!--
ew_CreateEditor();  // Create DHTML editor(s)

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php include "footer.php" ?>
<?php
$psacar_news_edit->Page_Terminate();
?>
<?php

//
// Page class
//
class cpsacar_news_edit {

	// Page ID
	var $PageID = 'edit';

	// Table name
	var $TableName = 'psacar_news';

	// Page object name
	var $PageObjName = 'psacar_news_edit';

	// Page name
	function PageName() {
		return ew_CurrentPage();
	}

	// Page URL
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		global $psacar_news;
		if ($psacar_news->UseTokenInUrl) $PageUrl .= "t=" . $psacar_news->TableVar . "&"; // Add page token
		return $PageUrl;
	}

	// Page URLs
	var $AddUrl;
	var $EditUrl;
	var $CopyUrl;
	var $DeleteUrl;
	var $ViewUrl;
	var $ListUrl;

	// Export URLs
	var $ExportPrintUrl;
	var $ExportHtmlUrl;
	var $ExportExcelUrl;
	var $ExportWordUrl;
	var $ExportXmlUrl;
	var $ExportCsvUrl;

	// Update URLs
	var $InlineAddUrl;
	var $InlineCopyUrl;
	var $InlineEditUrl;
	var $GridAddUrl;
	var $GridEditUrl;
	var $MultiDeleteUrl;
	var $MultiUpdateUrl;

	// Message
	function getMessage() {
		return @$_SESSION[EW_SESSION_MESSAGE];
	}

	function setMessage($v) {
		if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Append
			$_SESSION[EW_SESSION_MESSAGE] .= "<br>" . $v;
		} else {
			$_SESSION[EW_SESSION_MESSAGE] = $v;
		}
	}

	// Show message
	function ShowMessage() {
		$sMessage = $this->getMessage();
		$this->Message_Showing($sMessage);
		if ($sMessage <> "") { // Message in Session, display
			echo "<p><span class=\"ewMessage\">" . $sMessage . "</span></p>";
			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
		}
	}

	// Validate page request
	function IsPageRequest() {
		global $objForm, $psacar_news;
		if ($psacar_news->UseTokenInUrl) {
			if ($objForm)
				return ($psacar_news->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($psacar_news->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

	//
	// Page class constructor
	//
	function cpsacar_news_edit() {
		global $conn, $Language;

		// Language object
		$Language = new cLanguage();

		// Table object (psacar_news)
		$GLOBALS["psacar_news"] = new cpsacar_news();

		// Table object (psacar_user)
		$GLOBALS['psacar_user'] = new cpsacar_user();

		// Page ID
		if (!defined("EW_PAGE_ID"))
			define("EW_PAGE_ID", 'edit', TRUE);

		// Table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'psacar_news', TRUE);

		// Start timer
		$GLOBALS["gsTimer"] = new cTimer();

		// Open connection
		$conn = ew_Connect();
	}

	// 
	//  Page_Init
	//
	function Page_Init() {
		global $gsExport, $gsExportFile, $UserProfile, $Language, $Security, $objForm;
		global $psacar_news;

		// Security
		$Security = new cAdvancedSecurity();
		if (!$Security->IsLoggedIn()) $Security->AutoLogin();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}

		// Create form object
		$objForm = new cFormObj();

		// Global Page Loading event (in userfn*.php)
		Page_Loading();

		// Page Load event
		$this->Page_Load();
	}

	//
	// Page_Terminate
	//
	function Page_Terminate($url = "") {
		global $conn;

		// Page Unload event
		$this->Page_Unload();

		// Global Page Unloaded event (in userfn*.php)
		Page_Unloaded();

		 // Close connection
		$conn->Close();

		// Go to URL if specified
		$this->Page_Redirecting($url);
		if ($url <> "") {
			if (!EW_DEBUG_ENABLED && ob_get_length())
				ob_end_clean();
			header("Location: " . $url);
		}
		exit();
	}
	var $sDbMasterFilter;
	var $sDbDetailFilter;

	// 
	// Page main
	//
	function Page_Main() {
		global $objForm, $Language, $gsFormError, $psacar_news;

		// Load key from QueryString
		if (@$_GET["id"] <> "")
			$psacar_news->id->setQueryStringValue($_GET["id"]);
		if (@$_POST["a_edit"] <> "") {
			$psacar_news->CurrentAction = $_POST["a_edit"]; // Get action code
			$this->GetUploadFiles(); // Get upload files
			$this->LoadFormValues(); // Get form values

			// Validate form
			if (!$this->ValidateForm()) {
				$psacar_news->CurrentAction = ""; // Form error, reset action
				$this->setMessage($gsFormError);
				$psacar_news->EventCancelled = TRUE; // Event cancelled
				$this->RestoreFormValues();
			}
		} else {
			$psacar_news->CurrentAction = "I"; // Default action is display
		}

		// Check if valid key
		if ($psacar_news->id->CurrentValue == "")
			$this->Page_Terminate("psacar_newslist.php"); // Invalid key, return to list
		switch ($psacar_news->CurrentAction) {
			case "I": // Get a record to display
				if (!$this->LoadRow()) { // Load record based on key
					$this->setMessage($Language->Phrase("NoRecord")); // No record found
					$this->Page_Terminate("psacar_newslist.php"); // No matching record, return to list
				}
				break;
			Case "U": // Update
				$psacar_news->SendEmail = TRUE; // Send email on update success
				if ($this->EditRow()) { // Update record based on key
					$this->setMessage($Language->Phrase("UpdateSuccess")); // Update success
					$sReturnUrl = $psacar_news->getReturnUrl();
					$this->Page_Terminate($sReturnUrl); // Return to caller
				} else {
					$psacar_news->EventCancelled = TRUE; // Event cancelled
					$this->RestoreFormValues(); // Restore form values if update failed
				}
		}

		// Render the record
		$psacar_news->RowType = EW_ROWTYPE_EDIT; // Render as Edit
		$this->RenderRow();
	}

	// Get upload files
	function GetUploadFiles() {
		global $objForm, $psacar_news;

		// Get upload data
			if ($psacar_news->image_news->Upload->UploadFile()) {

				// No action required
			} else {
				echo $psacar_news->image_news->Upload->Message;
				$this->Page_Terminate();
				exit();
			}
			if ($psacar_news->thumbnail_news->Upload->UploadFile()) {

				// No action required
			} else {
				echo $psacar_news->thumbnail_news->Upload->Message;
				$this->Page_Terminate();
				exit();
			}
	}

	// Load form values
	function LoadFormValues() {

		// Load from form
		global $objForm, $psacar_news;
		$psacar_news->id->setFormValue($objForm->GetValue("x_id"));
		$psacar_news->news_cat_id->setFormValue($objForm->GetValue("x_news_cat_id"));
		$psacar_news->title->setFormValue($objForm->GetValue("x_title"));
		$psacar_news->name->setFormValue($objForm->GetValue("x_name"));
		$psacar_news->short_description->setFormValue($objForm->GetValue("x_short_description"));
		$psacar_news->description->setFormValue($objForm->GetValue("x_description"));
		$psacar_news->notify->setFormValue($objForm->GetValue("x_notify"));
		$psacar_news->is_show->setFormValue($objForm->GetValue("x_is_show"));
		$psacar_news->post_date->setFormValue($objForm->GetValue("x_post_date"));
		$psacar_news->post_date->CurrentValue = ew_UnFormatDateTime($psacar_news->post_date->CurrentValue, 5);
		$psacar_news->created_date->setFormValue($objForm->GetValue("x_created_date"));
		$psacar_news->created_date->CurrentValue = ew_UnFormatDateTime($psacar_news->created_date->CurrentValue, 5);
		$psacar_news->modified_date->setFormValue($objForm->GetValue("x_modified_date"));
		$psacar_news->modified_date->CurrentValue = ew_UnFormatDateTime($psacar_news->modified_date->CurrentValue, 5);
	}

	// Restore form values
	function RestoreFormValues() {
		global $objForm, $psacar_news;
		$this->LoadRow();
		$psacar_news->id->CurrentValue = $psacar_news->id->FormValue;
		$psacar_news->news_cat_id->CurrentValue = $psacar_news->news_cat_id->FormValue;
		$psacar_news->title->CurrentValue = $psacar_news->title->FormValue;
		$psacar_news->name->CurrentValue = $psacar_news->name->FormValue;
		$psacar_news->short_description->CurrentValue = $psacar_news->short_description->FormValue;
		$psacar_news->description->CurrentValue = $psacar_news->description->FormValue;
		$psacar_news->notify->CurrentValue = $psacar_news->notify->FormValue;
		$psacar_news->is_show->CurrentValue = $psacar_news->is_show->FormValue;
		$psacar_news->post_date->CurrentValue = $psacar_news->post_date->FormValue;
		$psacar_news->post_date->CurrentValue = ew_UnFormatDateTime($psacar_news->post_date->CurrentValue, 5);
		$psacar_news->created_date->CurrentValue = $psacar_news->created_date->FormValue;
		$psacar_news->created_date->CurrentValue = ew_UnFormatDateTime($psacar_news->created_date->CurrentValue, 5);
		$psacar_news->modified_date->CurrentValue = $psacar_news->modified_date->FormValue;
		$psacar_news->modified_date->CurrentValue = ew_UnFormatDateTime($psacar_news->modified_date->CurrentValue, 5);
	}

	// Load row based on key values
	function LoadRow() {
		global $conn, $Security, $psacar_news;
		$sFilter = $psacar_news->KeyFilter();

		// Call Row Selecting event
		$psacar_news->Row_Selecting($sFilter);

		// Load SQL based on filter
		$psacar_news->CurrentFilter = $sFilter;
		$sSql = $psacar_news->SQL();
		$res = FALSE;
		$rs = ew_LoadRecordset($sSql);
		if ($rs && !$rs->EOF) {
			$res = TRUE;
			$this->LoadRowValues($rs); // Load row values

			// Call Row Selected event
			$psacar_news->Row_Selected($rs);
			$rs->Close();
		}
		return $res;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $conn, $psacar_news;
		$psacar_news->id->setDbValue($rs->fields('id'));
		$psacar_news->news_cat_id->setDbValue($rs->fields('news_cat_id'));
		$psacar_news->title->setDbValue($rs->fields('title'));
		$psacar_news->name->setDbValue($rs->fields('name'));
		$psacar_news->short_description->setDbValue($rs->fields('short_description'));
		$psacar_news->description->setDbValue($rs->fields('description'));
		$psacar_news->notify->setDbValue($rs->fields('notify'));
		$psacar_news->is_show->setDbValue($rs->fields('is_show'));
		$psacar_news->post_date->setDbValue($rs->fields('post_date'));
		$psacar_news->created_date->setDbValue($rs->fields('created_date'));
		$psacar_news->modified_date->setDbValue($rs->fields('modified_date'));
		$psacar_news->image_news->Upload->DbValue = $rs->fields('image_news');
		$psacar_news->thumbnail_news->Upload->DbValue = $rs->fields('thumbnail_news');
	}

	// Render row values based on field settings
	function RenderRow() {
		global $conn, $Security, $Language, $psacar_news;

		// Initialize URLs
		// Call Row_Rendering event

		$psacar_news->Row_Rendering();

		// Common render codes for all row types
		// id

		$psacar_news->id->CellCssStyle = ""; $psacar_news->id->CellCssClass = "";
		$psacar_news->id->CellAttrs = array(); $psacar_news->id->ViewAttrs = array(); $psacar_news->id->EditAttrs = array();

		// news_cat_id
		$psacar_news->news_cat_id->CellCssStyle = ""; $psacar_news->news_cat_id->CellCssClass = "";
		$psacar_news->news_cat_id->CellAttrs = array(); $psacar_news->news_cat_id->ViewAttrs = array(); $psacar_news->news_cat_id->EditAttrs = array();

		// title
		$psacar_news->title->CellCssStyle = ""; $psacar_news->title->CellCssClass = "";
		$psacar_news->title->CellAttrs = array(); $psacar_news->title->ViewAttrs = array(); $psacar_news->title->EditAttrs = array();

		// name
		$psacar_news->name->CellCssStyle = ""; $psacar_news->name->CellCssClass = "";
		$psacar_news->name->CellAttrs = array(); $psacar_news->name->ViewAttrs = array(); $psacar_news->name->EditAttrs = array();

		// short_description
		$psacar_news->short_description->CellCssStyle = ""; $psacar_news->short_description->CellCssClass = "";
		$psacar_news->short_description->CellAttrs = array(); $psacar_news->short_description->ViewAttrs = array(); $psacar_news->short_description->EditAttrs = array();

		// description
		$psacar_news->description->CellCssStyle = ""; $psacar_news->description->CellCssClass = "";
		$psacar_news->description->CellAttrs = array(); $psacar_news->description->ViewAttrs = array(); $psacar_news->description->EditAttrs = array();

		// notify
		$psacar_news->notify->CellCssStyle = ""; $psacar_news->notify->CellCssClass = "";
		$psacar_news->notify->CellAttrs = array(); $psacar_news->notify->ViewAttrs = array(); $psacar_news->notify->EditAttrs = array();

		// is_show
		$psacar_news->is_show->CellCssStyle = ""; $psacar_news->is_show->CellCssClass = "";
		$psacar_news->is_show->CellAttrs = array(); $psacar_news->is_show->ViewAttrs = array(); $psacar_news->is_show->EditAttrs = array();

		// post_date
		$psacar_news->post_date->CellCssStyle = ""; $psacar_news->post_date->CellCssClass = "";
		$psacar_news->post_date->CellAttrs = array(); $psacar_news->post_date->ViewAttrs = array(); $psacar_news->post_date->EditAttrs = array();

		// created_date
		$psacar_news->created_date->CellCssStyle = ""; $psacar_news->created_date->CellCssClass = "";
		$psacar_news->created_date->CellAttrs = array(); $psacar_news->created_date->ViewAttrs = array(); $psacar_news->created_date->EditAttrs = array();

		// modified_date
		$psacar_news->modified_date->CellCssStyle = ""; $psacar_news->modified_date->CellCssClass = "";
		$psacar_news->modified_date->CellAttrs = array(); $psacar_news->modified_date->ViewAttrs = array(); $psacar_news->modified_date->EditAttrs = array();

		// image_news
		$psacar_news->image_news->CellCssStyle = ""; $psacar_news->image_news->CellCssClass = "";
		$psacar_news->image_news->CellAttrs = array(); $psacar_news->image_news->ViewAttrs = array(); $psacar_news->image_news->EditAttrs = array();

		// thumbnail_news
		$psacar_news->thumbnail_news->CellCssStyle = ""; $psacar_news->thumbnail_news->CellCssClass = "";
		$psacar_news->thumbnail_news->CellAttrs = array(); $psacar_news->thumbnail_news->ViewAttrs = array(); $psacar_news->thumbnail_news->EditAttrs = array();
		if ($psacar_news->RowType == EW_ROWTYPE_VIEW) { // View row

			// id
			$psacar_news->id->ViewValue = $psacar_news->id->CurrentValue;
			$psacar_news->id->CssStyle = "";
			$psacar_news->id->CssClass = "";
			$psacar_news->id->ViewCustomAttributes = "";

			// news_cat_id
			if (strval($psacar_news->news_cat_id->CurrentValue) <> "") {
				$sFilterWrk = "`id` = " . ew_AdjustSql($psacar_news->news_cat_id->CurrentValue) . "";
			$sSqlWrk = "SELECT `title` FROM `psacar_news_category`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
				$rswrk = $conn->Execute($sSqlWrk);
				if ($rswrk && !$rswrk->EOF) { // Lookup values found
					$psacar_news->news_cat_id->ViewValue = $rswrk->fields('title');
					$rswrk->Close();
				} else {
					$psacar_news->news_cat_id->ViewValue = $psacar_news->news_cat_id->CurrentValue;
				}
			} else {
				$psacar_news->news_cat_id->ViewValue = NULL;
			}
			$psacar_news->news_cat_id->CssStyle = "";
			$psacar_news->news_cat_id->CssClass = "";
			$psacar_news->news_cat_id->ViewCustomAttributes = "";

			// title
			$psacar_news->title->ViewValue = $psacar_news->title->CurrentValue;
			$psacar_news->title->CssStyle = "";
			$psacar_news->title->CssClass = "";
			$psacar_news->title->ViewCustomAttributes = "";

			// name
			$psacar_news->name->ViewValue = $psacar_news->name->CurrentValue;
			$psacar_news->name->CssStyle = "";
			$psacar_news->name->CssClass = "";
			$psacar_news->name->ViewCustomAttributes = "";

			// short_description
			$psacar_news->short_description->ViewValue = $psacar_news->short_description->CurrentValue;
			$psacar_news->short_description->CssStyle = "";
			$psacar_news->short_description->CssClass = "";
			$psacar_news->short_description->ViewCustomAttributes = "";

			// description
			$psacar_news->description->ViewValue = $psacar_news->description->CurrentValue;
			$psacar_news->description->CssStyle = "";
			$psacar_news->description->CssClass = "";
			$psacar_news->description->ViewCustomAttributes = "";

			// notify
			$psacar_news->notify->ViewValue = $psacar_news->notify->CurrentValue;
			$psacar_news->notify->CssStyle = "";
			$psacar_news->notify->CssClass = "";
			$psacar_news->notify->ViewCustomAttributes = "";

			// is_show
			if (strval($psacar_news->is_show->CurrentValue) <> "") {
				$psacar_news->is_show->ViewValue = "";
				$arwrk = explode(",", strval($psacar_news->is_show->CurrentValue));
				for ($ari = 0; $ari < count($arwrk); $ari++) {
					switch (trim($arwrk[$ari])) {
						case "1":
							$psacar_news->is_show->ViewValue .= "Show";
							break;
						default:
							$psacar_news->is_show->ViewValue .= trim($arwrk[$ari]);
					}
					if ($ari < count($arwrk)-1) $psacar_news->is_show->ViewValue .= ew_ViewOptionSeparator($ari);
				}
			} else {
				$psacar_news->is_show->ViewValue = NULL;
			}
			$psacar_news->is_show->CssStyle = "";
			$psacar_news->is_show->CssClass = "";
			$psacar_news->is_show->ViewCustomAttributes = "";

			// post_date
			$psacar_news->post_date->ViewValue = $psacar_news->post_date->CurrentValue;
			$psacar_news->post_date->ViewValue = ew_FormatDateTime($psacar_news->post_date->ViewValue, 5);
			$psacar_news->post_date->CssStyle = "";
			$psacar_news->post_date->CssClass = "";
			$psacar_news->post_date->ViewCustomAttributes = "";

			// created_date
			$psacar_news->created_date->ViewValue = $psacar_news->created_date->CurrentValue;
			$psacar_news->created_date->ViewValue = ew_FormatDateTime($psacar_news->created_date->ViewValue, 5);
			$psacar_news->created_date->CssStyle = "";
			$psacar_news->created_date->CssClass = "";
			$psacar_news->created_date->ViewCustomAttributes = "";

			// modified_date
			$psacar_news->modified_date->ViewValue = $psacar_news->modified_date->CurrentValue;
			$psacar_news->modified_date->ViewValue = ew_FormatDateTime($psacar_news->modified_date->ViewValue, 5);
			$psacar_news->modified_date->CssStyle = "";
			$psacar_news->modified_date->CssClass = "";
			$psacar_news->modified_date->ViewCustomAttributes = "";

			// image_news
			if (!ew_Empty($psacar_news->image_news->Upload->DbValue)) {
				$psacar_news->image_news->ViewValue = $psacar_news->image_news->Upload->DbValue;
			} else {
				$psacar_news->image_news->ViewValue = "";
			}
			$psacar_news->image_news->CssStyle = "";
			$psacar_news->image_news->CssClass = "";
			$psacar_news->image_news->ViewCustomAttributes = "";

			// thumbnail_news
			if (!ew_Empty($psacar_news->thumbnail_news->Upload->DbValue)) {
				$psacar_news->thumbnail_news->ViewValue = $psacar_news->thumbnail_news->Upload->DbValue;
				$psacar_news->thumbnail_news->ImageWidth = 80;
				$psacar_news->thumbnail_news->ImageHeight = 80;
				$psacar_news->thumbnail_news->ImageAlt = $psacar_news->thumbnail_news->FldAlt();
			} else {
				$psacar_news->thumbnail_news->ViewValue = "";
			}
			$psacar_news->thumbnail_news->CssStyle = "";
			$psacar_news->thumbnail_news->CssClass = "";
			$psacar_news->thumbnail_news->ViewCustomAttributes = "";

			// id
			$psacar_news->id->HrefValue = "";
			$psacar_news->id->TooltipValue = "";

			// news_cat_id
			$psacar_news->news_cat_id->HrefValue = "";
			$psacar_news->news_cat_id->TooltipValue = "";

			// title
			$psacar_news->title->HrefValue = "";
			$psacar_news->title->TooltipValue = "";

			// name
			$psacar_news->name->HrefValue = "";
			$psacar_news->name->TooltipValue = "";

			// short_description
			$psacar_news->short_description->HrefValue = "";
			$psacar_news->short_description->TooltipValue = "";

			// description
			$psacar_news->description->HrefValue = "";
			$psacar_news->description->TooltipValue = "";

			// notify
			$psacar_news->notify->HrefValue = "";
			$psacar_news->notify->TooltipValue = "";

			// is_show
			$psacar_news->is_show->HrefValue = "";
			$psacar_news->is_show->TooltipValue = "";

			// post_date
			$psacar_news->post_date->HrefValue = "";
			$psacar_news->post_date->TooltipValue = "";

			// created_date
			$psacar_news->created_date->HrefValue = "";
			$psacar_news->created_date->TooltipValue = "";

			// modified_date
			$psacar_news->modified_date->HrefValue = "";
			$psacar_news->modified_date->TooltipValue = "";

			// image_news
			if (!ew_Empty($psacar_news->image_news->Upload->DbValue)) {
				$psacar_news->image_news->HrefValue = ew_UploadPathEx(FALSE, $psacar_news->image_news->UploadPath) . ((!empty($psacar_news->image_news->ViewValue)) ? $psacar_news->image_news->ViewValue : $psacar_news->image_news->CurrentValue);
				if ($psacar_news->Export <> "") $psacar_news->image_news->HrefValue = ew_ConvertFullUrl($psacar_news->image_news->HrefValue);
			} else {
				$psacar_news->image_news->HrefValue = "";
			}
			$psacar_news->image_news->TooltipValue = "";

			// thumbnail_news
			$psacar_news->thumbnail_news->HrefValue = "";
			$psacar_news->thumbnail_news->TooltipValue = "";
		} elseif ($psacar_news->RowType == EW_ROWTYPE_EDIT) { // Edit row

			// id
			$psacar_news->id->EditCustomAttributes = "";
			$psacar_news->id->EditValue = $psacar_news->id->CurrentValue;
			$psacar_news->id->CssStyle = "";
			$psacar_news->id->CssClass = "";
			$psacar_news->id->ViewCustomAttributes = "";

			// news_cat_id
			$psacar_news->news_cat_id->EditCustomAttributes = "";
				$sFilterWrk = "";
			$sSqlWrk = "SELECT `id`, `title`, '' AS Disp2Fld, '' AS SelectFilterFld FROM `psacar_news_category`";
			$sWhereWrk = "";
			if ($sFilterWrk <> "") {
				if ($sWhereWrk <> "") $sWhereWrk .= " AND ";
				$sWhereWrk .= "(" . $sFilterWrk . ")";
			}
			if ($sWhereWrk <> "") $sSqlWrk .= " WHERE " . $sWhereWrk;
			$rswrk = $conn->Execute($sSqlWrk);
			$arwrk = ($rswrk) ? $rswrk->GetRows() : array();
			if ($rswrk) $rswrk->Close();
			array_unshift($arwrk, array("", $Language->Phrase("PleaseSelect")));
			$psacar_news->news_cat_id->EditValue = $arwrk;

			// title
			$psacar_news->title->EditCustomAttributes = "";
			$psacar_news->title->EditValue = ew_HtmlEncode($psacar_news->title->CurrentValue);

			// name
			$psacar_news->name->EditCustomAttributes = "";
			$psacar_news->name->EditValue = ew_HtmlEncode($psacar_news->name->CurrentValue);

			// short_description
			$psacar_news->short_description->EditCustomAttributes = "";
			$psacar_news->short_description->EditValue = ew_HtmlEncode($psacar_news->short_description->CurrentValue);

			// description
			$psacar_news->description->EditCustomAttributes = "";
			$psacar_news->description->EditValue = ew_HtmlEncode($psacar_news->description->CurrentValue);

			// notify
			$psacar_news->notify->EditCustomAttributes = "";
			$psacar_news->notify->EditValue = ew_HtmlEncode($psacar_news->notify->CurrentValue);

			// is_show
			$psacar_news->is_show->EditCustomAttributes = "";
			$arwrk = array();
			$arwrk[] = array("1", "Show");
			$psacar_news->is_show->EditValue = $arwrk;

			// post_date
			$psacar_news->post_date->EditCustomAttributes = "";
			$psacar_news->post_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_news->post_date->CurrentValue, 5));

			// created_date
			$psacar_news->created_date->EditCustomAttributes = "";
			$psacar_news->created_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_news->created_date->CurrentValue, 5));

			// modified_date
			$psacar_news->modified_date->EditCustomAttributes = "";
			$psacar_news->modified_date->EditValue = ew_HtmlEncode(ew_FormatDateTime($psacar_news->modified_date->CurrentValue, 5));

			// image_news
			$psacar_news->image_news->EditCustomAttributes = "";
			if (!ew_Empty($psacar_news->image_news->Upload->DbValue)) {
				$psacar_news->image_news->EditValue = $psacar_news->image_news->Upload->DbValue;
			} else {
				$psacar_news->image_news->EditValue = "";
			}

			// thumbnail_news
			$psacar_news->thumbnail_news->EditCustomAttributes = "";
			if (!ew_Empty($psacar_news->thumbnail_news->Upload->DbValue)) {
				$psacar_news->thumbnail_news->EditValue = $psacar_news->thumbnail_news->Upload->DbValue;
				$psacar_news->thumbnail_news->ImageWidth = 80;
				$psacar_news->thumbnail_news->ImageHeight = 80;
				$psacar_news->thumbnail_news->ImageAlt = $psacar_news->thumbnail_news->FldAlt();
			} else {
				$psacar_news->thumbnail_news->EditValue = "";
			}

			// Edit refer script
			// id

			$psacar_news->id->HrefValue = "";

			// news_cat_id
			$psacar_news->news_cat_id->HrefValue = "";

			// title
			$psacar_news->title->HrefValue = "";

			// name
			$psacar_news->name->HrefValue = "";

			// short_description
			$psacar_news->short_description->HrefValue = "";

			// description
			$psacar_news->description->HrefValue = "";

			// notify
			$psacar_news->notify->HrefValue = "";

			// is_show
			$psacar_news->is_show->HrefValue = "";

			// post_date
			$psacar_news->post_date->HrefValue = "";

			// created_date
			$psacar_news->created_date->HrefValue = "";

			// modified_date
			$psacar_news->modified_date->HrefValue = "";

			// image_news
			if (!ew_Empty($psacar_news->image_news->Upload->DbValue)) {
				$psacar_news->image_news->HrefValue = ew_UploadPathEx(FALSE, $psacar_news->image_news->UploadPath) . ((!empty($psacar_news->image_news->EditValue)) ? $psacar_news->image_news->EditValue : $psacar_news->image_news->CurrentValue);
				if ($psacar_news->Export <> "") $psacar_news->image_news->HrefValue = ew_ConvertFullUrl($psacar_news->image_news->HrefValue);
			} else {
				$psacar_news->image_news->HrefValue = "";
			}

			// thumbnail_news
			$psacar_news->thumbnail_news->HrefValue = "";
		}

		// Call Row Rendered event
		if ($psacar_news->RowType <> EW_ROWTYPE_AGGREGATEINIT)
			$psacar_news->Row_Rendered();
	}

	// Validate form
	function ValidateForm() {
		global $Language, $gsFormError, $psacar_news;

		// Initialize form error message
		$gsFormError = "";
		if (!ew_CheckFileType($psacar_news->image_news->Upload->FileName)) {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("WrongFileType");
		}
		if ($psacar_news->image_news->Upload->FileSize > 0 && EW_MAX_FILE_SIZE > 0 && $psacar_news->image_news->Upload->FileSize > EW_MAX_FILE_SIZE) {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= str_replace("%s", EW_MAX_FILE_SIZE, $Language->Phrase("MaxFileSize"));
		}
		if (!ew_CheckFileType($psacar_news->thumbnail_news->Upload->FileName)) {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $Language->Phrase("WrongFileType");
		}
		if ($psacar_news->thumbnail_news->Upload->FileSize > 0 && EW_MAX_FILE_SIZE > 0 && $psacar_news->thumbnail_news->Upload->FileSize > EW_MAX_FILE_SIZE) {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= str_replace("%s", EW_MAX_FILE_SIZE, $Language->Phrase("MaxFileSize"));
		}

		// Check if validation required
		if (!EW_SERVER_VALIDATE)
			return ($gsFormError == "");
		if (!ew_CheckInteger($psacar_news->notify->FormValue)) {
			if ($gsFormError <> "") $gsFormError .= "<br>";
			$gsFormError .= $psacar_news->notify->FldErrMsg();
		}
		if (!ew_CheckDate($psacar_news->post_date->FormValue)) {
			if ($gsFormError <> "") $gsFormError .= "<br>";
			$gsFormError .= $psacar_news->post_date->FldErrMsg();
		}
		if (!ew_CheckDate($psacar_news->created_date->FormValue)) {
			if ($gsFormError <> "") $gsFormError .= "<br>";
			$gsFormError .= $psacar_news->created_date->FldErrMsg();
		}
		if (!ew_CheckDate($psacar_news->modified_date->FormValue)) {
			if ($gsFormError <> "") $gsFormError .= "<br>";
			$gsFormError .= $psacar_news->modified_date->FldErrMsg();
		}

		// Return validate result
		$ValidateForm = ($gsFormError == "");

		// Call Form_CustomValidate event
		$sFormCustomError = "";
		$ValidateForm = $ValidateForm && $this->Form_CustomValidate($sFormCustomError);
		if ($sFormCustomError <> "") {
			$gsFormError .= ($gsFormError <> "") ? "<br>" : "";
			$gsFormError .= $sFormCustomError;
		}
		return $ValidateForm;
	}

	// Update record based on key values
	function EditRow() {
            global $conn, $Security, $Language, $psacar_news;
            $sFilter = $psacar_news->KeyFilter();
            $psacar_news->CurrentFilter = $sFilter;
            $sSql = $psacar_news->SQL();
            $conn->raiseErrorFn = 'ew_ErrorFn';
            $rs = $conn->Execute($sSql);
            $conn->raiseErrorFn = '';
            if ($rs === FALSE)
                return FALSE;
            
            if ($rs->EOF) {
                $EditRow = FALSE; // Update Failed
            } 
            else {
                // Save old values
                $rsold =& $rs->fields;
                $rsnew = array();

                // news_cat_id
                $psacar_news->news_cat_id->SetDbValueDef($rsnew, $psacar_news->news_cat_id->CurrentValue, NULL, FALSE);

                // title
                $psacar_news->title->SetDbValueDef($rsnew, $psacar_news->title->CurrentValue, NULL, FALSE);

                // name
                $psacar_news->name->SetDbValueDef($rsnew, $psacar_news->name->CurrentValue, NULL, FALSE);

                // short_description
                $psacar_news->short_description->SetDbValueDef($rsnew, $psacar_news->short_description->CurrentValue, NULL, FALSE);

                // description
                $psacar_news->description->SetDbValueDef($rsnew, $psacar_news->description->CurrentValue, NULL, FALSE);

                // notify
                $psacar_news->notify->SetDbValueDef($rsnew, $psacar_news->notify->CurrentValue, NULL, FALSE);

                // is_show
                $psacar_news->is_show->SetDbValueDef($rsnew, $psacar_news->is_show->CurrentValue, NULL, FALSE);

                // post_date
                $psacar_news->post_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_news->post_date->CurrentValue, 5, FALSE), NULL);

                // created_date
                $psacar_news->created_date->SetDbValueDef($rsnew, ew_UnFormatDateTime($psacar_news->created_date->CurrentValue, 5, FALSE), NULL);

                // modified_date
                $psacar_news->modified_date->SetDbValueDef($rsnew, ew_UnFormatDateTime(date("Y-m-d H:i:s"), 5, FALSE), NULL);

                // image_news
                $psacar_news->image_news->Upload->SaveToSession(); // Save file value to Session
                if ($psacar_news->image_news->Upload->Action == "2" || $psacar_news->image_news->Upload->Action == "3") { // Update/Remove
                    $psacar_news->image_news->Upload->DbValue = $rs->fields('image_news'); // Get original value
                    if (is_null($psacar_news->image_news->Upload->Value)) {
                            $rsnew['image_news'] = NULL;
                    }
                    else {
                        $rsnew['image_news'] = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $psacar_news->image_news->UploadPath), $psacar_news->image_news->Upload->FileName);
                    }
                }

                // thumbnail_news
                $psacar_news->thumbnail_news->Upload->SaveToSession(); // Save file value to Session
                if ($psacar_news->thumbnail_news->Upload->Action == "2" || $psacar_news->thumbnail_news->Upload->Action == "3") { // Update/Remove
                    $psacar_news->thumbnail_news->Upload->DbValue = $rs->fields('thumbnail_news'); // Get original value
                    if (is_null($psacar_news->thumbnail_news->Upload->Value)) {
                            $rsnew['thumbnail_news'] = NULL;
                    } 
                    else {
                            $rsnew['thumbnail_news'] = ew_UploadFileNameEx(ew_UploadPathEx(TRUE, $psacar_news->thumbnail_news->UploadPath), $psacar_news->thumbnail_news->Upload->FileName);
                    }
                }

                // Call Row Updating event
                $bUpdateRow = $psacar_news->Row_Updating($rsold, $rsnew);
                if ($bUpdateRow) {
                    if (!ew_Empty($psacar_news->image_news->Upload->Value)) {
                            $psacar_news->image_news->Upload->SaveToFile($psacar_news->image_news->UploadPath, $rsnew['image_news'], FALSE);
                    }
                    if (!ew_Empty($psacar_news->thumbnail_news->Upload->Value)) {
                            $psacar_news->thumbnail_news->Upload->SaveToFile($psacar_news->thumbnail_news->UploadPath, $rsnew['thumbnail_news'], FALSE);
                    }
                    $conn->raiseErrorFn = 'ew_ErrorFn';
                                                
                    $EditRow = $conn->Execute($psacar_news->UpdateSQL($rsnew));
                    $conn->raiseErrorFn = '';
                } 
                else {
                    if ($psacar_news->CancelMessage <> "") {
                            $this->setMessage($psacar_news->CancelMessage);
                            $psacar_news->CancelMessage = "";
                    } 
                    else {
                            $this->setMessage($Language->Phrase("UpdateCancelled"));
                    }
                    $EditRow = FALSE;
                }
            }

            // Call Row_Updated event
            if ($EditRow)
                $psacar_news->Row_Updated($rsold, $rsnew);
            $rs->Close();

            // image_news
            $psacar_news->image_news->Upload->RemoveFromSession(); // Remove file value from Session

            // thumbnail_news
            $psacar_news->thumbnail_news->Upload->RemoveFromSession(); // Remove file value from Session
            return $EditRow;
	}

	// Page Load event
	function Page_Load() {

            //echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

            //echo "Page Unload";
	}

	// Page Redirecting event
	function Page_Redirecting(&$url) {

            // Example:
            //$url = "your URL";

	}

	// Message Showing event
	function Message_Showing(&$msg) {

            // Example:
            //$msg = "your new message";

	}

	// Form Custom Validate event
	function Form_CustomValidate(&$CustomError) {

            // Return error message in CustomError
            return TRUE;
	}
}
?>
